package com.his.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.his.common.PageParam;
import com.his.common.Rsp;
import com.his.entity.DoctorAdviceAction;
import com.his.mapper.DoctorAdviceActionMapper;
import com.his.service.DoctorAdviceActionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DoctorAdviceAction)表服务实现类
 *
 * @author makejava
 * @since 2020-10-23 18:08:12
 */
@Service("doctorAdviceActionService")
public class DoctorAdviceActionServiceImpl implements DoctorAdviceActionService {
    @Resource
    private DoctorAdviceActionMapper doctorAdviceActionMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DoctorAdviceAction queryById(Integer id) {
        return this.doctorAdviceActionMapper.queryById(id);
    }

    /**
     * 查询所有通过实体类属性
     *
     * @param pageParam 实例对象
     * @return 查询的结果
     */
    @Override
    public Rsp queryAll(PageParam<DoctorAdviceAction> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        //排序
        for (int i = 0; i < pageParam.getOrderParams().length; i++) {
            PageHelper.orderBy(pageParam.getOrderParams()[i]);
        }
        List<DoctorAdviceAction> list = this.doctorAdviceActionMapper.queryAll(pageParam.getModel());
        return Rsp.success(new PageInfo<>(list));
    }

    /**
     * 新增数据
     *
     * @param doctorAdviceAction 实例对象
     * @return 实例对象
     */
    @Override
    public DoctorAdviceAction insert(DoctorAdviceAction doctorAdviceAction) {
        this.doctorAdviceActionMapper.insert(doctorAdviceAction);
        return doctorAdviceAction;
    }

    /**
     * 修改数据
     *
     * @param doctorAdviceAction 实例对象
     * @return 实例对象
     */
    @Override
    public DoctorAdviceAction update(DoctorAdviceAction doctorAdviceAction) {
        this.doctorAdviceActionMapper.update(doctorAdviceAction);
        return this.queryById(doctorAdviceAction.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.doctorAdviceActionMapper.deleteById(id) > 0;
    }

    @Override
    public DoctorAdviceAction queryByAdviceId(String id) {

        DoctorAdviceAction doctorAdviceAction = doctorAdviceActionMapper.queryByAdviceId(Integer.parseInt(id));

        return doctorAdviceAction;
    }
}
